What could cause a string subscript out of range error in a C loop while accessing string elements